﻿using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging.Configuration;
using Microsoft.Extensions.Logging.Console;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.CompilerServices;

namespace BasicLoggerModule.Model
{
    public static class SqlServerILoggerExtensions
    {
        public static ILoggingBuilder AddSqlserver(this ILoggingBuilder builder)
        {
            builder.AddProvider(new SqlserverProveder());
            return builder;
        }

        public static void LogInfoDefine(this ILogger logger, string Message, [CallerMemberName] string memberName = "", [CallerFilePath] string filePath = "", [CallerLineNumber] int lineNumber = 0)
        {
            logger.LogInformation($"[{memberName} in {filePath}:{lineNumber}] {Message}");
        }

        // 日志记录方法，包括调用者信息
        public static void LogDebugDefine(this ILogger logger, string message, [CallerMemberName] string memberName = "", [CallerFilePath] string filePath = "", [CallerLineNumber] int lineNumber = 0)
        {
            logger.LogDebug($"[{memberName} in {filePath}:{lineNumber}] {message}");
        }

        public static void LogInformationDefine(this ILogger logger, string message, [CallerMemberName] string memberName = "", [CallerFilePath] string filePath = "", [CallerLineNumber] int lineNumber = 0)
        {
            logger.LogInformation($"[{memberName} in {filePath}:{lineNumber}] {message}");
        }

        public static void LogWarningDefine(this ILogger logger, string message, [CallerMemberName] string memberName = "", [CallerFilePath] string filePath = "", [CallerLineNumber] int lineNumber = 0)
        {
            logger.LogWarning($"[{memberName} in {filePath}:{lineNumber}] {message}");
        }

        public static void LogErrorDefine(this ILogger logger, string message, [CallerMemberName] string memberName = "", [CallerFilePath] string filePath = "", [CallerLineNumber] int lineNumber = 0)
        {
            logger.LogError($"[{memberName} in {filePath}:{lineNumber}] {message}");
        }

        public static void LogCriticalDefine(this ILogger logger, string message, [CallerMemberName] string memberName = "", [CallerFilePath] string filePath = "", [CallerLineNumber] int lineNumber = 0)
        {
            logger.LogCritical($"[{memberName} in {filePath}:{lineNumber}] {message}");
        }
    }
}
